package view.full.event;

import java.awt.BorderLayout;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import view.full.FullViewer;
import event.model.Dsek;
import event.model.Event;

@SuppressWarnings("serial")
public class EventItem extends JPanel implements MouseListener, FocusListener {

	private Event e;
	
	public EventItem (Event e) {
		this.e = e;
		addMouseListener(this);
		addFocusListener(this);
		setLayout(new BorderLayout());
		
		// Top information
		JPanel titleBar = new JPanel();
		titleBar.setLayout(new BorderLayout());
		JLabel title = new JLabel(e.getTitle() + "("+e.getWhen()+")");
		title.setFont(FullViewer.TITLE_FONT);
		title.setBackground(FullViewer.BACKGROUNDCOLOR);
		JLabel ratio;
		if (e.getSpots() == 0) {
			ratio = new JLabel("Alla är välkommna!");
		} else {
			ratio = new JLabel(e.getFreeSpots() + "/" + e.getSpots() + " platser kvar");			
		}
		titleBar.add(title,BorderLayout.WEST);
		titleBar.add(ratio,BorderLayout.EAST);
		
		// The text field
		JTextArea text = new JTextArea(e.getInfo());
		text.addMouseListener(this);
		JScrollPane textPane = new JScrollPane(text);
		text.setEditable(false);
		text.setLineWrap(true);
		text.setBackground(FullViewer.BACKGROUNDCOLOR);
		
		
		// Bottom part
		JPanel bottomPanel = new JPanel();
		bottomPanel.setLayout(new BorderLayout());
		JLabel emptyLine = new JLabel(" ");
		JPanel bottomInfo = new JPanel();
		bottomInfo.setLayout(new BorderLayout());
		JLabel arranger = new JLabel("Arangeras av: " + e.getArranges());
		JLabel open;
		if (e.isOpen()) {
			open = new JLabel("Anmälan öppen tills: " + e.getCloses());
		} else {
			open = new JLabel("Anmälan är stängd");
		}
		bottomInfo.add(arranger,BorderLayout.WEST);
		bottomInfo.add(open,BorderLayout.EAST);
		bottomPanel.add(bottomInfo,BorderLayout.NORTH);
		bottomPanel.add(emptyLine,BorderLayout.SOUTH);
		
		// Adding all parts to the display
		add(titleBar,BorderLayout.NORTH);
		add(textPane,BorderLayout.CENTER);
		add(bottomPanel,BorderLayout.SOUTH);
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
	
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		
		EventInfoBox box = new EventInfoBox(new Dsek(),this.e);
		
		box.showAndBlipp();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}

	@Override
	public void focusGained(FocusEvent arg0) {
	
	}

	@Override
	public void focusLost(FocusEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
